package com.fp.m7.client;

import net.customware.gwt.presenter.client.EventBus;

import com.fp.m7.client.event.AccountAuthenticatedEvent;
import com.fp.m7.shared.dto.AccountDto;
import com.google.inject.Inject;

/**
 * AccountDto placeholder. GIN will take care of keeping only 1 instance of this class, and inject it to presenters
 * which need information about the logged user. Setting an auth account fires an AccountAuthenticatedEvent.
 * 
 * @author 7
 */
public class AccountContext {

    private AccountDto authenticatedAccount;
    private EventBus eventBus;

    @Inject
    public AccountContext(EventBus eventBus) {
        this.eventBus = eventBus;
    }

    public AccountDto getAuthenticatedAccount() {
        return authenticatedAccount;
    }

    public void setAuthenticatedAccount(AccountDto authenticatedAccount) {
        this.authenticatedAccount = authenticatedAccount;
        eventBus.fireEvent(new AccountAuthenticatedEvent(authenticatedAccount));
    }

}
